package com.toommi.refuse.common.enums;

/**
 * ..
 * 事件状态枚举
 *
 * @author yangg
 * @since 2019-07-26 11:44
 */
public enum WorkStatusEnum {
    /**
     * 待处理
     */

    SUBMITTED(0, "待分派"),

    TODO(1, "待处理"),

    DOING(2, "处理中"),

    DONE(3, "已处理"),


    END(999, "end");

    private int code;

    private String note;

    public int getCode() {
        return code;
    }

    public String getNote() {
        return note;
    }

    WorkStatusEnum(int code, String note) {
        this.code = code;
        this.note = note;
    }

    /**
     * 校验状态值是否合法
     *
     * @param code 状态值
     * @return 校验结果
     */
    public static boolean hasValue(int code) {
        for (WorkStatusEnum statusEnum : WorkStatusEnum.values()) {
            if (statusEnum.getCode() == code) {
                return true;
            }
        }
        return false;
    }

    /**
     * 根据code查找状态信息
     *
     * @param code 状态标识
     * @return 对应枚举
     */
    public static WorkStatusEnum getByCode(int code) {
        for (WorkStatusEnum statusEnum : WorkStatusEnum.values()) {
            if (statusEnum.getCode() == code) {
                return statusEnum;
            }
        }
        return END;
    }
}
